import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get.dart';
import 'package:open_eye/base/controller/base_controller.dart';
import 'package:open_eye/base/pageWidget/base_stateless_widget.dart';

class ImageFitTest extends BaseStatelessWidget<ImageFitTestController> {
  @override
  Widget buildContent(BuildContext context) {
    return NestedScrollView(
      body: Container(
        padding: EdgeInsets.fromLTRB(20.0, 100.0, 20.0, 20.0),
        child: Column(
          children: [
            ElevatedButton(
                onPressed: () {
                  showToast("点击了按钮");
                },
                child: Text("Nomal")),
          ],
        ),
      ),
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
        return <Widget>[
          SliverAppBar(
              title: Text("复仇者联盟"),
              expandedHeight: 230.0,
              pinned: true,
              flexibleSpace: FlexibleSpaceBar(
                  title: Text("复仇者"),
                  background: Image.network(
                      'http://img.haote.com/upload/20180918/2018091815372344164.jpg',
                      fit: BoxFit.fitHeight))),
          SliverPersistentHeader(
              pinned: true,
              delegate: StickyTabBarDelegate(
                  child:
                  TabBar(
                      labelColor: Colors.black,
                      tabs: <Widget>[Tab(text: "热点"), Tab(text: "收藏")])))
        ];
      },
    );
  }

  @override
  String titleString() {
    return "imagefit";
  }

  @override
  bool showTitleBar() {
    return true;
  }

  @override
  bool useLoadSir() => false;
}

class ImageFitTestController extends BaseController {
  @override
  void loadNet() {
    // TODO: implement loadNet
  }
}

class ImageFitTestBinding extends Bindings {
  @override
  void dependencies() {
    Get.lazyPut(() => ImageFitTestController());
  }
}

class StickyTabBarDelegate extends SliverPersistentHeaderDelegate {
  final TabBar child;

  StickyTabBarDelegate({required this.child});

  @override
  Widget build(BuildContext context, double shrinkOffset,
      bool overlapsContent) {
    return Container(
      color: Theme
          .of(context)
          .backgroundColor,
      child: this.child,
    );
  }

  @override
  double get maxExtent => this.child.preferredSize.height;

  @override
  double get minExtent => this.child.preferredSize.height;

  @override
  bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
    return true;
  }
}
